SOURCE_DIR = ./{{cookiecutter.project_slug}}

.PHONY: clean help

help:
	clear;
	@echo "================= Usage =================";
	@echo "clean                  : Remove autogenerated folders";
	@echo "clean-pyc              : Remove python artifacts."
	@echo "clean-build            : Remove build artifacts."
	@echo "bandit                 : Install and run bandit security analysis.";
	@echo "mypy                   : Install and run mypy type checking.";
	@echo "flake8                 : Install and run flake8 linting.";
	@echo "install_requirements   : Install all the packages listed in txt files in requirements folder.";
	@echo "test                   : Run tests and generate coverage report.";
	@echo "build_whl              : Build a python wheel package.";

# Clean the folder from build/test related folders
clean: clean-build clean-pyc
	rm -rf .mypy_cache/ .pytest_cache/
	rm -f .coverage

clean-pyc:
	find . \( -name '*.pyc' -o -name '*.pyo' \) -exec rm -rf {} +

clean-build:
	rm -rf build/ dist/ *.egg-info

# Install all the packages listed in txt files in requirements folder.
install_requirements:
	find ./requirements -maxdepth 1 -name '*.txt' -exec python -m pip install -r {} \;

# Install and run bandit security analysis
bandit:
	python -m pip install bandit
	bandit -r $(SOURCE_DIR)

# Install and run mypy type checking
mypy:
	python -m pip install -r requirements/dev.txt
	mypy $(SOURCE_DIR)

# Install and run flake8 linting
flake8:
	python -m pip install flake8
	flake8 $(SOURCE_DIR)

# Install requirements for testing and run tests
test:
	python -m pip install -r requirements/dev.txt
	python -m pip install -e .
	pytest

# build wheel package
build_whl:
	python setup.py bdist_wheel